﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Enter.DataProxy.ProxyAdapter.Configuration
{
    /// <summary>
    /// 数据库节点（关联config文件中的connectionStrings）
    /// </summary>
    public class DatabaseElement : ConfigurationElement
    {
        public static readonly string NodeName = "database";
        private ConfigurationProperty _ReadonlyProperty;
        private ConfigurationProperty _WriteonlyProperty;

        /// <summary>
        /// 一组读写数据库的名称
        /// </summary>
        [ConfigurationProperty("name", IsKey = true, DefaultValue = "default")]
        public string Name
        {
            get { return (string)this["name"]; }
            set { this["name"] = value; }
        }

        /// <summary>
        /// 数据库只读链接
        /// </summary>
        public DatabaseReadonlyElement Readonly
        {
            get { return (DatabaseReadonlyElement)this[_ReadonlyProperty]; }
        }

        /// <summary>
        /// 数据库只写链接
        /// </summary>
        public DatabaseWriteonlyElement Writeonly
        {
            get { return (DatabaseWriteonlyElement)this[_WriteonlyProperty]; }
        }

        public DatabaseElement()
        {
            _ReadonlyProperty = new ConfigurationProperty(DatabaseReadonlyElement.NodeName, typeof(DatabaseReadonlyElement));
            _WriteonlyProperty = new ConfigurationProperty(DatabaseWriteonlyElement.NodeName, typeof(DatabaseWriteonlyElement));

            this.Properties.Add(_ReadonlyProperty);
            this.Properties.Add(_WriteonlyProperty);
        }
    }
}
